/**
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-09 17:24:08
 * Copyright (c) 2015- joysuch-版权所有
 */

package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.target.BpTargetDuty;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface BpTargetDutyDao extends JpaRepository<BpTargetDuty, Long>, JpaSpecificationExecutor<BpTargetDuty> {

    @Query(value = "select 1 from wwyt_bp_target_duty b where b.title=:title  and b.delete_state=1 and b.parent_id is null", nativeQuery = true)
    Integer countByTitle(String title);

    @Query("update BpTargetDuty b set b.state=0 where id=:id")
    @Modifying
    void nullify(Long id);

    @Query("update BpTargetDuty b set b.status=:status where b.id=:id")
    @Modifying
    void examineSet(Long id, Byte status);

    @Query(value = "select realName from wwyt_bp_target_duty where id = ?1", nativeQuery = true)
    public String getBaseUserNameById(Long id);


}
